<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>完成衔接</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="/static/css/default.css" rel="stylesheet" type="text/css" />
    <style>
        .discell {
            text-align:right;
            width:250px;
            font-size:12px;
        }
        .showcell {
            text-align:left;
            width:260px;
            font-size:10px;
        }
        table {
            border-collapse:separate;
            border:solid 1px #c9c9c9;
            padding-top:5px;
            padding-bottom:8px;
            border:none;
        }
        .redText {
            color:red;
        }
    </style>
</head>
<body>
<div class="mini-fit" style="padding-top:25px;margin-bottom:45px;">
    <form id="form1" method="post" style="height:100%;width: 100%;/*overflow-x: auto;overflow-y: auto;*/">
        <div>
            <#--唯一标识id-->
            <input name="id" id="id" class="mini-hidden" value="${id!''}" />
            <#--罪犯编号-->
            <input name="priNum" id="priNum" class="mini-hidden" value="${priNum!''}" />
            <input name="cjpgId" id="cjpgId" class="mini-hidden" value="" />
            <input name="secondStateXj" id="secondStateXj" class="mini-hidden" value="${secstatexj!''}" />
            <table class="form-table" align="center" style="border: solid 0px;">
                <tr>
                    <th colspan="1" style="text-align: left;font-size:15px">司法所衔接信息</th>
                </tr>
                <tr>
                    <td class="discell"><span style="color: red">*</span>衔接状态:</td>
                    <td class="showcell">
                        <input name="statexj" id="statexj" class="mini-radiobuttonlist"
                               data="[{ id: '1', text: '衔接成功' },{ id: '3', text: '衔接失败' }]"
                               textField="text" valueField="id" value="1" style="width:210px;" onvaluechanged="hiddenGa()" />
                    </td>
                </tr>
                <tr>
                    <td class="discell"><span style="color: red">*</span>安置帮教人员来源:</td>
                    <td class="showcell">
                        <input name="abpersontype" id="abpersontype" class="mini-combobox"
                               url="/search/code/native?1=1&codeType=1_34&pcodeId=-1"
                               textField="text" valueField="id" value="01" required="true" emptyText="请选择..." style="width:210px;"/>
                    </td>
                </tr>
                <tr>
                    <td class="discell"><span id='tip' style="color: red">*</span>上传衔接证据:</td>
                    <td class="showcell">
                        <input type="button" onclick="onFileUpload1()" value="上传文件" />
                        <span id="msg"></span>
                        <div><b>支持扩展名:</b>.rar .zip .doc .docx .xls .xlsx .pdf .jpg</div>
                        <#--<span class="redText">* 刑满释放人员通知书</span>-->
                    </td>
                    </td>
                </tr>
                <tr>
                    <td class="discell"><span style="color: red">*</span>备注:</td>
                    <td colspan="3" class="showcell">
                        <input class="mini-textarea" style="width:210px;height: 100px" required="true" emptyText="请输入..." id="remark" name="remark" />
                    </td>
                </tr>
            </table>
            <table id="gaTable" class="form-table" align="center" style="border: solid 0px;">
                <tr>
                    <th colspan="1" style="text-align: left;font-size:15px">通知公安机关</th>
                </tr>
                <tr>
                    <td class="discell">通知公安机关落实管控措施:</td>
                    <td class="showcell">
                        <input name="Gongan" id="Gongan" class="mini-radiobuttonlist"
                               data="[{ id: '1', text: '是' },{ id: '2', text: '否' }]"
                               textField="text" valueField="id" value="2" style="width:210px;" onvaluechanged="change()" />
                    </td>
                </tr>
                <tr>
                    <td class="discell"><span class="redText" id="gauser">* </span>公安联系人:</td>
                    <td colspan="3" class="showcell">
                        <input class="mini-textbox" emptyText="请输入公安联系人" id="galxr" name="galxr" style="width:210px;" />
                    </td>
                </tr>
                <#--联系方式修改为固话+电话-->
                <input id="galxfs" name="galxfs" hidden />
                <tr>
                    <td class="discell"><span class="redText"></span>公安手机号码:</td>
                    <td>
                        <input class="mini-textbox" emptyText="请输入手机号码" id="gaPhone" name="gaPhone" style="width:210px;" onblur="checkPhone(2)"/>
                    </td>
                </tr>
                <tr>
                    <td class="discell"><span class="redText"></span>公安固话:</td>
                    <td>
                        <input class="mini-textbox" emptyText="请输入固定电话" id="gaTel" name="gaTel" style="width:210px;" onblur="checkPhone(1)"/>
                    </td>
                </tr>
                <tr>
                    <td class="discell"><span class="redText" id="gafj">* </span>附件上传:</td>
                    <td colspan="3" class="showcell">
                        <input id="gafile" type="button" onclick="onFileUpload2()" value="上传文件" />
                        <span class="redText" id="gatishi">* 公安附件</span>
                        <span id="msg1"></span>
                        <div><b>支持扩展名:</b>.rar .zip .doc .docx .xls .xlsx .pdf .jpg</div>
                    </td>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</div>
<div style="width:100%;position:absolute;bottom:0;line-height: 45px;border-top: 1px solid #dfdfdf;text-align: center">
    <a class="mini-button" iconCls="fa-save" plain="true" style="font-size: 15px" onclick="saveData()">完成衔接</a>
</div>
<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("form1");
    var Gongan = mini.get("Gongan");
    var statexj = mini.get("statexj");
    var priNum = mini.get("priNum")
    var priNums = priNum.value;
    var id = mini.get("id");
    var ids = id.value;
    var tasknum = 0;
    //是否 通知公安机关落实管控措施 标识 1：是 ""：否
    var flag = 1;
    if (Gongan.getValue() === "2") {
        var galxr = mini.get("galxr");
        var gaPhone = mini.get("gaPhone");
        var gaTel = mini.get("gaTel");
        var gafile = mini.get("gafile");
        galxr.setEnabled(false);
        galxr.setRequired(false);
        gaTel.setEnabled(false);
        gaTel.setRequired(false);
        gaPhone.setEnabled(false);
        gaPhone.setRequired(false);
        document.getElementById("gafile").setAttribute("disabled", true);//设置不可点击
        document.getElementById("gatishi").setAttribute("hidden", true);//设置隐藏
        document.getElementById("gauser").setAttribute("hidden", true);//设置隐藏
        document.getElementById("gafj").setAttribute("hidden", true);//设置隐藏
        flag = "";
    }

    function hiddenGa() {
        if (statexj.getValue() === "3") {
            document.getElementById("gaTable").setAttribute("hidden", true);
            //删除必填的那个*提示
            document.getElementById("tip").setAttribute("hidden", true);
            //点击衔接失败时，将gongan设为否
            Gongan.setValue(2);
            flag = "";
            var galxr = mini.get("galxr");
            var gaPhone = mini.get("gaPhone");
            var gaTel = mini.get("gaTel");
            $("galxr").removeClass("mini-textbox");
            $("gaPhone").removeClass("mini-textbox");
            $("gaTel").removeClass("mini-textbox");
            galxr.setEnabled(false);
            galxr.setValue("");
            gaPhone.setEnabled(false);
            gaPhone.setValue("");
            gaTel.setEnabled(false);
            gaTel.setValue("");
            document.getElementById('galxr').classList.remove("mini-textbox"); //移除class
            document.getElementById('gaPhone').classList.remove("mini-textbox"); //移除class
            document.getElementById('gaPhone').classList.remove("mini-textbox"); //移除class
            document.getElementById('galxr').className = 'mini-textbox'; //设置为新的
            document.getElementById('gaTel').className = 'mini-textbox'; //设置为新的
            document.getElementById('gaTel').className = 'mini-textbox'; //设置为新的
            document.getElementById("gafile").setAttribute("disabled", true);//设置不可点击
            document.getElementById("gatishi").setAttribute("hidden", true);//设置隐藏
            document.getElementById("gauser").setAttribute("hidden", true);//设置隐藏
            document.getElementById("gafj").setAttribute("hidden", true);//设置隐藏
        } else {
            document.getElementById("gaTable").removeAttribute("hidden");
            document.getElementById("tip").removeAttribute("hidden");
        }
    }

    function saveData() {
        form.validate();
        if (form.isValid() == false) {
            return;
        }
        if (statexj.getValue() == '1' && tasknum <= 0) {
            mini.alert("请上传衔接证据！");
            return;
        }
        // 校验电话号码
        var tel = mini.get("gaTel").getValue();
        var phone = mini.get("gaPhone").getValue();
        var newPhone = checkTelAndPhone(tel,phone);
        var flagPhone = newPhone['flag'];
        var kflag = newPhone['kflag'];
        if(Gongan.getValue() === "1" && '-1'===kflag){
            mini.alert("请至少输入一个联系方式");
            return;
        }
        if(!flagPhone){
            mini.alert("固定电话或手机号码有误，请重填");
            return;
        }
        var data = form.getData();
        data.taskId = "10";
        data.galxfs = newPhone['newTelAndPhone'];
        var json = mini.encode(data);
        if (Gongan.getValue() === "1") {
            if (checkPhone(1) == false) {
                return;
            }
            if (checkPhone(2) == false) {
                return;
            }
        }

        if (statexj.getValue() == 3) {
            $.ajax({
                url: "/azbj/yazgj/xj/deleteUploadFile",
                data: {priNum: priNums, id: ids},
                type: "post",
                success: function (obj) {
                }
            })
        }

        mini.confirm("确定要完成衔接?","确定?",function(action){
            if (action == "ok"){
                $.ajax({
                    url: "/azbj/yazgl/xj/save/fj",
                    data: {data: json, flag: flag},
                    type: "post",
                    success: function (success) {
                        if (success.code == 1) {
                            mini.alert("保存成功", "成功", window.CloseOwnerWindow);
                        } else if (success.code == -3) {
                            mini.alert("请上传衔接证据！");
                        } else if (success.code == -2) {
                            mini.alert("请上传公安附件！");
                        } else if (success.code == 5599) {
                            mini.alert(success.message);
                        } else {
                            mini.alert("保存失败");
                        }
                    }
                })
            }else{
                return;
            }
        })
    }

    // 上传附件 taskId=10 代表衔接附件上传
    function onFileUpload1() {
        commonEdit("/upload/user/uploadAppendixfile/view?1=1&id=${id!''}&priNum=${priNum!''}&taskId=10", null, null, 600, 400, true, true, true, callback);
        function callback() {
            $.ajax({
                url: "/upload/downloadAppendixFile/getCountall?1=1&priNum=${priNum!''}&taskId=10",
                type: "get",
                success: function (success) {
                    $("#msg").text("上传成功" + success.data + "条!");
                    tasknum = success.data;
                }
            })
            grid.reload();
        }
    }

    // 上传附件 taskId=11 代表公安附件上传
    function onFileUpload2() {
        commonEdit("/upload/user/uploadAppendixfile/view?1=1&id=${id!''}&priNum=${priNum!''}&taskId=11", null, null, 600, 400, true, true,true, callback);
        // 回调函数
        function callback() {
            $.ajax({
                url: "/upload/downloadAppendixFile/getCountall?1=1&priNum=${priNum!''}&taskId=11",
                type: "get",
                success: function (success) {
                    $("#msg1").text("上传成功" + success.data + "条!");
                }
            })
            grid.reload();
        }
    }

    function change() {
        if (Gongan.getValue() === "1") {
            flag = 1;
            var galxr = mini.get("galxr");
            var gaPhone = mini.get("gaPhone");
            var gaTel = mini.get("gaTel");
            galxr.setEnabled(true);
            galxr.setRequired(true);
            gaPhone.setEnabled(true);
            gaPhone.setRequired(false);
            gaTel.setEnabled(true);
            gaTel.setRequired(false);
            document.getElementById("gatishi").removeAttribute("hidden");//设置隐藏
            document.getElementById("gauser").removeAttribute("hidden");//设置隐藏
            document.getElementById("gafj").removeAttribute("hidden");//设置隐藏
            document.getElementById("gafile").removeAttribute("disabled");//设置不可点击
        }
        if (Gongan.getValue() === "2") {
            flag = "";
            var galxr = mini.get("galxr");
            var gaPhone = mini.get("gaPhone");
            var gaTel = mini.get("gaTel");
            $("galxr").removeClass("mini-textbox");
            $("gaPhone").removeClass("mini-textbox");
            $("gaTel").removeClass("mini-textbox");
            galxr.setEnabled(false);
            galxr.setValue("");
            gaPhone.setEnabled(false);
            gaPhone.setValue("");
            gaTel.setEnabled(false);
            gaTel.setValue("");
            document.getElementById('galxr').classList.remove("mini-textbox"); //移除class
            document.getElementById('gaPhone').classList.remove("mini-textbox"); //移除class
            document.getElementById('gaPhone').classList.remove("mini-textbox"); //移除class
            document.getElementById('galxr').className = 'mini-textbox'; //设置为新的
            document.getElementById('gaTel').className = 'mini-textbox'; //设置为新的
            document.getElementById('gaPhone').className = 'mini-textbox'; //设置为新的
            document.getElementById("gafile").setAttribute("disabled", true);//设置不可点击
            document.getElementById("gatishi").setAttribute("hidden", true);//设置隐藏
            document.getElementById("gauser").setAttribute("hidden", true);//设置隐藏
            document.getElementById("gafj").setAttribute("hidden", true);//设置隐藏
        }
    }

    //电话号码的验证
    function checkPhone(e){
        var phone = mini.get("gaPhone").getValue();
        var telPhone = mini.get("gaTel").getValue();
        if (e == '1') {
            if(telPhone != '' && !validateTel(telPhone)) {
                mini.alert("固定电话有误，请重填");
            }
        }
        if (e == '2') {
            if(phone != '' && !validatePhone1(phone)) {
                mini.alert("手机号码有误，请重填");
            }
        }
    }

    window.onload = function () {
        var level = ${level};
        var abpersontype = mini.get("abpersontype");
        abpersontype.setEnabled(false);
        if(level == "01") {
            abpersontype.setValue("01");
        } else if (level == "02") {
            abpersontype.setValue("02");
        } else if (level == "05") {
            abpersontype.setValue("03");
        }
        $("#msg").text("上传成功" + ${count} + "条!")
        if (${count}>0) {
            tasknum = ${count};
        }
        $("#msg1").text("上传成功" + ${count1} + "条!")
        var secstatexj = ${secstatexj!''};
        // 二次衔接，只能衔接成功
        if (secstatexj == "0") {
            var statexj = mini.get("statexj");
            statexj.setValue("1");
            statexj.disable();
        }
    }
</script>
</body>
</html>